package store.lunangangster.engine.impl.util;

import java.util.HashSet;
import java.util.Set;
import store.lunangangster.engine.impl.entity.Entity;
import store.lunangangster.engine.impl.entity.ExecutionEntity;

public class EntityUtil {

  protected static final Set<Class<? extends Entity>> NOT_BATCH_INSERT_SET = new HashSet<>();

  static{
    // Execution存在自引用外键，batchInsert会出现错误
    NOT_BATCH_INSERT_SET.add(ExecutionEntity.class);
  }

  public static boolean hasNoId(Entity entity) {
    return entity == null || entity.getId() == null;
  }

  public static boolean isNeededId(Entity entity) {
    return entity != null && entity.getId() == null;
  }

  public static boolean allowBatchInsert(Class<? extends Entity> clazz) {
    for (Class<? extends Entity> aClass : NOT_BATCH_INSERT_SET) {
      if (aClass.isAssignableFrom(clazz)) {
        return false;
      }
    }
    return true;
  }
}
